'\" te
.\" Copyright (c) 2002, Sun Microsystems, Inc. All Rights Reserved
.\" Copyright 1989 AT&T
.\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License").  You may not use this file except in compliance with the License.
.\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing.  See the License for the specific language governing permissions and limitations under the License.
.\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE.  If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
.TH DIV 3C "Jul 24, 2002"
.SH NAME
div, ldiv, lldiv \- compute the quotient and remainder
.SH SYNOPSIS
.LP
.nf
#include <stdlib.h>

\fBdiv_t\fR \fBdiv\fR(\fBint\fR \fInumer\fR, \fBint\fR \fIdenom\fR);
.fi

.LP
.nf
\fBldiv_t\fR \fBldiv\fR(\fBlong int\fR \fInumer\fR, \fBlong int\fR \fIdenom\fR);
.fi

.LP
.nf
\fBlldiv_t\fR \fBlldiv\fR(\fBlong long\fR \fInumer\fR, \fBlong long\fR \fIdenom\fR);
.fi

.SH DESCRIPTION
.sp
.LP
The \fBdiv()\fR function computes the quotient and remainder of the division of
the numerator \fInumer\fR by the denominator \fIdenom\fR. It provides a
well-defined semantics for the signed integral division and remainder
operations, unlike the implementation-defined semantics of the built-in
operations.   The sign of the resulting quotient is that of the algebraic
quotient, and if the division is inexact, the magnitude of the resulting
quotient is the largest integer less than the magnitude of the algebraic
quotient. If the result cannot be  represented, the behavior is undefined;
otherwise, \fIquotient\fR * \fIdenom\fR + \fIremainder\fR will equal
\fInumer\fR.
.sp
.LP
The \fBldiv()\fR and \fBlldiv()\fR functions are similar to \fBdiv()\fR, except
that the arguments and the members of the returned structure are different.
The \fBldiv()\fR function returns a structure of type \fBldiv_t\fR and has type
\fBlong int\fR.  The \fBlldiv()\fR function returns a structure of type
\fBlldiv_t\fR and has type \fBlong long\fR.
.SH RETURN VALUES
.sp
.LP
The \fBdiv()\fR function returns a structure of type \fBdiv_t\fR, comprising
both the quotient and remainder:
.sp
.in +2
.nf
int   quot;   /*quotient*/
int   rem;    /*remainder*/
.fi
.in -2

.sp
.LP
The \fBldiv()\fR function returns a structure of type \fBldiv_t\fR and
\fBlldiv()\fR returns a structure of type \fBlldiv_t\fR, comprising both the
quotient and remainder:
.sp
.in +2
.nf
long int   quot;   /*quotient*/
long int   rem;    /*remainder*/
.fi
.in -2

.SH ATTRIBUTES
.sp
.LP
See \fBattributes\fR(7) for descriptions of the following attributes:
.sp

.sp
.TS
box;
c | c
l | l .
ATTRIBUTE TYPE	ATTRIBUTE VALUE
_
Interface Stability	Standard
_
MT-Level	MT-Safe
.TE

.SH SEE ALSO
.sp
.LP
.BR attributes (7),
.BR standards (7)
